package com.adroiti.texasholdem.engine.combinations;

import java.util.Map;
import java.util.TreeMap;

import com.adroiti.texasholdem.Combination;
import com.adroiti.texasholdem.engine.CombinationFactory;

public class SimpleCombinationFactory implements CombinationFactory {

	/**
	 * We will take TreeMap instead of HashMap only to ease my burden of making
	 * hashCode for classes :D
	 */
	private Map<String, Combination> combinations = new TreeMap<String, Combination>();

	@Override
	public Combination getCombination(String name) {
		Combination combi;
		combi = combinations.get(name);
		if (combi == null) {
			try {
				combi = (Combination) Class.forName(
						"com.adroiti.texasholdem.engine.combinations." + name)
						.newInstance();
				combinations.put(name, combi);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return combi;
	}

}
